/**
 * Copyright(c) 2010 Ceno Techonologies Co., Ltd.
 *
 * History:
 *   15-2-3 下午5:52 Created by lyyang
 */
package com.jade.bss.web.resolver;

import com.jade.bss.admin.account.AdminAccount;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import java.io.Serializable;

/**
 * 管理员封装类,用于resolver
 *
 * @author <a href="mailto:lyyang@ceno.cn">lyyang</a>
 * @version 1.0 15-1-21 下午5:05
 */
public class AdminCapsule implements Serializable
{
    private AdminAccount admin;

    public AdminCapsule(){

    }

    public AdminCapsule(AdminAccount admin){
        this.admin = admin;
    }

    public void setAdmin(AdminAccount admin)
    {
        this.admin = admin;
    }

    public AdminAccount unwrap(){
        if (admin==null){
            Subject subject = SecurityUtils.getSubject();
            if (subject.getPrincipal() instanceof  AdminAccount){
                admin = (AdminAccount)subject.getPrincipal();
            }
        }
        return admin;
    }
}